<?php
namespace zake\foundation\stream;

use zake\foundation\able\stream\WriteAble;
use zake\foundation\able\traits\ResourceTrait;
use zake\foundation\able\traits\WriteTrait;
use zake\helper\Console;

/**
 * Class WriteStream
 * @package zake\foundation\stream
 *
 */
class WriteStream implements WriteAble
{
    use ResourceTrait,WriteTrait;

    // write 模式
    const MODE_ONCE     = 0b00000001;   // 写一次
    const MODE_PERSIST  = 0b00000010;   // 同步写完
    const ENCODE        = 0b00000100;   // 编码
    const UN_ENCODE     = 0b00001000;   // 非编码


    /**
     *
     * @param $resource
     * @return static
     *
     * @author liu.bin 2020-05-19 14:59
     */
    public static function create($resource)
    {
        return new static($resource);
    }

    /**
     * 构造器
     *
     * ReadStream constructor.
     * @param $resource
     */
    protected function __construct($resource)
    {
        $this->resource = $resource;
        $this->fd = (int)$resource;
    }

    public function __destruct()
    {
        Console::success("write stream __destruct");
    }
}